home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / gnulib / libsrc98.zoo / signal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-10  |  2.0 KB  |  98 lines

  1. /*
  2.  *        Cross Development System for Atari ST 
  3.  *     Copyright (c) 1988, Memorial University of Newfoundland
  4.  *
  5.  *   Signal routine - the signals are actually done by calling the _do_signal
  6.  * routine - similiar to kill() I guess.
  7.  *
  8.  * 1.3 ERS added SIGABRT handling, generally fixed up stuff
  9.  * 1.2 ERS added kill, changed _do_signal to an internal function
  10.  *
  11.  */
  12. #include    <signal.h>
  13. #include    <errno.h>
  14. #include    <string.h>
  15. #include    <unistd.h>
  16.  
  17. extern int __check_signals;        /* used in console i/o routines */
  18. #define SIG_EXIT    10        /* exit code */
  19.  
  20. struct sigarray_str {
  21.       __Sigfunc s_func;
  22. };
  23. /* SIG_DFL == 0, so everything is implicitly set to this */
  24. /* vector giving which signals are currently blocked from delivery (for TOS) */
  25. long _sigmask;
  26.  
  27. /* vector giving an indication of which signals are currently pending (for TOS) */
  28. long _sigpending;
  29.  
  30. static struct sigarray_str    sig_array[NSIG] ;
  31.  
  32. void
  33. _init_signal()            /* needed for dumping */
  34. {
  35.     bzero(sig_array, sizeof(sig_array)); /* for now */
  36.     _sigpending = _sigmask = 0;
  37. }
  38.  
  39. __Sigfunc signal(sig, func)
  40.     int    sig;
  41.       __Sigfunc func;
  42. {
  43.       __Sigfunc oldfunc;
  44.  
  45.     switch (sig) {
  46.     case SIGINT:
  47.     case SIGQUIT:
  48.         if (func != SIG_IGN)
  49.             __check_signals |= (sig==SIGINT ? 1 : 2);
  50.         else
  51.             __check_signals &= (sig==SIGINT ? ~1 : ~2);
  52.         /* falltrough */
  53.     case SIGALRM:
  54.     case SIGABRT:
  55.         oldfunc = sig_array[sig].s_func;
  56.         sig_array[sig].s_func = func;
  57.         break;
  58.     default:
  59.         errno = EINVAL;
  60.         oldfunc = SIG_ERR;
  61.     }
  62.     return oldfunc;
  63. }
  64.  
  65. static void
  66. _do_signal(sig)
  67.     int    sig;
  68. {
  69.       __Sigfunc func;
  70.  
  71.     if (sig >= 0 && sig < NSIG) {
  72.         func = sig_array[sig].s_func;
  73.         if (func == SIG_DFL)
  74.             switch (sig) {
  75.             case SIGQUIT:
  76.             case SIGINT:
  77.             case SIGALRM:
  78.             case SIGABRT:
  79.                 psignal(sig, "fatal signal received");
  80.                 _exit(SIG_EXIT + sig);
  81.             }
  82.         else if (func != SIG_IGN)
  83.             (*func)(sig);
  84.         /* else ignore it */
  85.     }
  86. }
  87.  
  88. int kill(pid, sig)
  89.     int pid, sig;
  90. {
  91.     if (pid != getpid()) {
  92.         errno = EACCESS;    /* I don't know if this is right */
  93.         return -1;
  94.     }
  95.     _do_signal(sig);
  96.     return 0;
  97. }
  98.